package jinyilw.common.ffmpeg;

import java.util.HashSet;
import java.util.Set;

/**
 * 视频压缩时采用x264编码器时需要指定的视频质量值
 */
public enum CrfValueEnum
{
	LOW_QUALITY("低质量", 28), MEDIUM_QUALITY("中等质量", 26), HIGH_QUALITY("高质量", 23);

	private String name;
	private int code;
	private static Set<Integer> TYPE_CODE_SET = new HashSet<>();

	static
	{
		CrfValueEnum[] types = CrfValueEnum.values();
		for (CrfValueEnum type : types)
		{
			TYPE_CODE_SET.add(type.getCode());
		}
	}

	CrfValueEnum(String typeName, int typeCode)
	{
		this.name = typeName;
		this.code = typeCode;
	}

	public static boolean isValid(int typeCode)
	{
		return TYPE_CODE_SET.contains(typeCode);
	}

	public static CrfValueEnum convertToEnum(int typeCode)
	{
		if (!isValid(typeCode))
		{
			return null;
		}
		for (CrfValueEnum type : CrfValueEnum.values())
		{
			if (typeCode == type.getCode())
			{
				return type;
			}
		}
		return null;
	}

	public boolean isEqual(int typeCode)
	{
		return this.code == typeCode;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public int getCode()
	{
		return code;
	}

	public void setCode(int code)
	{
		this.code = code;
	}

	public static Set<Integer> getTypeCodeSet()
	{
		return TYPE_CODE_SET;
	}

	public static void setTypeCodeSet(Set<Integer> typeCodeSet)
	{
		TYPE_CODE_SET = typeCodeSet;
	}
}
